//
//  FTSideHeaderView.m
//  FaceTo
//
//  Created by 姚冬元 on 2017/7/25.
//  Copyright © 2017年 chengbangming. All rights reserved.
//

#import "FTSideHeaderView.h"

@implementation FTSideHeaderView

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        [self initUI];
    }
    return self;
}

- (void)initUI
{
    self.backgroundColor = WhiteColor;
    
    _bgImgView = [[UIImageView alloc] init];
    _bgImgView.image = [UIImage imageNamed:@"Icon-120"];
    [self addSubview:_bgImgView];
    
    _avatar = [[UIImageView alloc] init];
    _avatar.image = [UIImage imageNamed:@"Icon-120"];
    [self addSubview:_avatar];
    
    _avatar.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色
    _avatar.layer.shadowOffset = CGSizeMake(3,3);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    _avatar.layer.shadowOpacity = 0.6;//阴影透明度，默认0
    _avatar.layer.shadowRadius = 3;//阴影半径，默认3
    
    [_bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.top.offset(0);
        make.width.mas_equalTo(kSCREEN_WIDTH*0.3);
        make.height.mas_equalTo(kSCREEN_WIDTH*0.3);
    }];
    
    [_avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(_bgImgView.mas_bottom);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    
    // 头像裁圆
    UIImage *image = [UIImage imageNamed:@"Icon-120"];
    //1.开启一个位图上下文(大小跟图片一样大)
    UIGraphicsBeginImageContext(image.size);
    //2.做裁剪.(对之前已经画上去的东西,不会有做用.)
    //2.1 bezierPathWithOvalInRect方法后面传的Rect,可以看作(x,y,width,height),前两个参数是裁剪的中心点,后面两个决定裁剪的区域是圆形还是椭圆.
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    //把路径设置为裁剪区域(超出裁剪区域以外的内容会自动裁剪掉.)
    [path addClip];
    //3.把图片绘制到上下文当中
    [image drawAtPoint:CGPointZero];
    //4.从上下文当中生成一张图片
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    //5.关闭上下文
    UIGraphicsEndImageContext();
    //6.把图片显示出来
    _avatar.image = newImage;
    
    //添加手势
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickedTheImage)];//响应方法没写
//    headImage.userInteractionEnabled=YES;   ///必须设置用户交互，手势才有用
//    [headImage addGestureRecognizer:tap];

   

}

@end
